package calvin.study.rabbitmq.advanced.custom;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;

import calvin.study.rabbitmq.base.RabbitMqBase;

public class Consumer extends RabbitMqBase {
	
	public static void main(String[] args) throws Exception {

		// 1 创建ConnectionFactory
		ConnectionFactory connectionFactory = getConnectionFactory();

		// 2 获取C onnection
		Connection connection = connectionFactory.newConnection();

		// 3 通过Connection创建一个新的Channel
		Channel channel = connection.createChannel();

		String exchangeName = "confirm_topic_exchange";
		String routingKey = "confirm.#";
		String queueName = "confirm_queue";

		// 4 声明交换机和队列 然后进行绑定设置, 最后制定路由Key
		channel.exchangeDeclare(exchangeName, "topic", true,false,null);
		channel.queueDeclare(queueName, true, false, false, null);
		channel.queueBind(queueName, exchangeName, routingKey);

		// 5 创建消费者
		channel.basicConsume(queueName, true, new CustomConsumer(channel));
	}

}
